﻿using strange.extensions.context.api;
using strange.extensions.dispatcher.eventdispatcher.api;
using strange.extensions.mediation.impl;
using System;
using System.Collections.Generic;


namespace CommonIoC
{
    public class TopButtonListPanelMediator : Mediator
    {

       

        [Inject]
        public TopButtonListPanelView view { get; set; }
        [Inject(ContextKeys.CONTEXT_DISPATCHER)]//全局的dispatcher
        public IEventDispatcher dispatcher { get; set; }

        public override void OnRegister()
        {
           
            dispatcher.AddListener(  MainUITouchEvnet.OpenTopMenuButtonList , onOpenTopMenuButtonList);

            dispatcher.AddListener(  PersonListPanelEvent.ClickBack , onOpenTopMenuButtonList );
            dispatcher.AddListener( PersonZhuangBeiBagEvent.ClickBack, onOpenTopMenuButtonList );



            dispatcher.AddListener(  HelperMsgPanelEvent.ClickBack, onOpenTopMenuButtonList);


            AddPersonListButtonClickFunc();
            AddHelperButtonClickFunc();
            AddBackButtonClickFunc();
          //  dispatcher.AddListener(PlayerGameState.CanMove_And_CanTouchWSAD, onCanMove_And_CanTouchWSAD);

        }

        private void onOpenTopMenuButtonList(IEvent payload)
        {
            view.ShowThisUI();
        }


        void AddPersonListButtonClickFunc()
        {
            if (view.btn_top_person != null)
            {
                view.btn_top_person.onClick.AddListener(delegate ()
                {

                    dispatcher.Dispatch( TopButtonListEvent.ClickPersonList );
                    view.CloseThisUI();
                });
            }
        }


        void AddHelperButtonClickFunc()
        {
            if (view.btn_top_helper != null)
            {
                view.btn_top_helper.onClick.AddListener(delegate ()
                {

                    dispatcher.Dispatch(TopButtonListEvent.ClickHelper);
                    view.CloseThisUI();
                });
            }
        }

        void AddBackButtonClickFunc()
        {
            if (view.btn_top_back != null)
            {
                view.btn_top_back.onClick.AddListener(delegate ()
                {

                    dispatcher.Dispatch(TopButtonListEvent.ClickBack);
                    view.CloseThisUI();
                });
            }
        }

        public override void OnRemove()
        {
            dispatcher.RemoveListener(MainUITouchEvnet.OpenTopMenuButtonList, onOpenTopMenuButtonList);
            //dispatcher.RemoveListener(PlayerStageCommandEvent.canMove, onPlayerStageChangeTocanMove);
            //dispatcher.RemoveListener(PlayerStageCommandEvent.doTalk, onPlayerStageChangeTodoTalk);

            //view.dispatcher.RemoveListener(GameEvent.InputKey, onInputKey);
        }


    }
}
